package com.westos.echufang.config;

import com.westos.echufang.config.handler.AlterPasswordIntercepter;
import com.westos.echufang.config.handler.LoginHandlerInterceptor;
import com.westos.echufang.config.handler.MailCheckIntercepter;
import com.westos.echufang.config.handler.RegistIntercepterHandle;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("index.html").setViewName("login/index");
        registry.addRedirectViewController("/","index.html");

        registry.addViewController("/main").setViewName("main");
        registry.addViewController("/findPwd").setViewName("login/findPwd");
        registry.addViewController("/mailVerification").setViewName("login/mailVerification");
        registry.addViewController("/alterPwd").setViewName("login/alterPwd");
        registry.addViewController("/alterSuccess").setViewName("login/alterSuccess");

        registry.addViewController("/toRegist").setViewName("regist/regist");
        registry.addViewController("/registSuccess").setViewName("regist/registSuccess");
        registry.addViewController("/mailCheck").setViewName("regist/mailCheck");

    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/main","/check1/**");
        registry.addInterceptor(new AlterPasswordIntercepter()).addPathPatterns("/mailVerification","/alterPwd");
        registry.addInterceptor(new MailCheckIntercepter()).addPathPatterns("/alterPwd");
        registry.addInterceptor(new RegistIntercepterHandle()).addPathPatterns("/mailCheck");
    }
}
